//
//  MainViewController.m
//  VidoarDemo
//
//  Created by xm on 2025/6/17.
//

#import "MainViewController.h"
#import "KeepLiveViewController.h"
#import "CallViewController.h"

@interface MainViewController ()

@property(nonatomic, strong) UIButton *keepLiveButton;
@property(nonatomic, strong) UIButton *callButton;
@property(nonatomic, strong) UIButton *WexinNotificationButton;


@end

@implementation MainViewController


static NSString* Color_Normal = @"5974A4";
static NSString* Color_Highlight = @"FF9700";





#pragma mark - init

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.log(@"Main");
    [self createdUI];
//
    
    [self  watch];
}

-(void) test
{
    //    self.log(@"[1] %@", m3_userDefaults.planLog);
    //    NSDictionary* data = data = @{
    //        @"task" : @{
    //            @"duration": @(10),
    //            @"lastDuration": @(20),
    //        }
    //    };
    //    m3_userDefaults.planLog = data;
    //
    //    self.log(@"[2] %@", m3_userDefaults.planLog);
    //
        
}


-(void) createdUI
{
    [self.view addSubview:self.keepLiveButton];
    [self.view addSubview:self.callButton];
    [self.view addSubview:self.WexinNotificationButton];
    
}

-(void) watch
{
    [[self.keepLiveButton rac_signalForControlEvents:UIControlEventTouchDown] subscribeNext:^(__kindof UIControl * _Nullable x) {
        UIViewController* vc = [[KeepLiveViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    }];
    
    [[self.callButton rac_signalForControlEvents:UIControlEventTouchDown] subscribeNext:^(__kindof UIControl * _Nullable x) {
        UIViewController* vc = [[CallViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    }];
    



}


#pragma  makr - getters

- (UIButton *)keepLiveButton
{
    if(_keepLiveButton){
        return _keepLiveButton;
    }
    
    CGRect frame = CGRectMake(20, NavAndStatusToolHeight + 20, screenWidth-40, 46);
    UIButton* button = [self createButtonWithTitle:@"App保活测试" frame:frame];
    
    _keepLiveButton = button;
    return _keepLiveButton;
    
}

- (UIButton *)callButton
{
    if(_callButton){
        return _callButton;
    }
    
    CGRect frame = CGRectMake(20, self.keepLiveButton.bottom + 10, screenWidth-40, 46);
    UIButton* button = [self createButtonWithTitle:@"来电测试" frame:frame];
    
    _callButton = button;
    return _callButton;
    
}

- (UIButton *)WexinNotificationButton
{
    if(_WexinNotificationButton){
        return _WexinNotificationButton;
    }
    
    CGRect frame = CGRectMake(20, self.callButton.bottom + 10, screenWidth-40, 46);
    UIButton* button = [self createButtonWithTitle:@"微信通知测试" frame:frame];
    
    _WexinNotificationButton = button;
    return _WexinNotificationButton;
    
}




#pragma mark - methods
-(UIButton*) createButtonWithTitle:(NSString*)title frame:(CGRect) frame
{
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    button.top = frame.origin.y;
    button.left = frame.origin.x;
    button.width = frame.size.width;
    button.height = frame.size.height;
    
    button.layer.cornerRadius = 5;
    button.layer.masksToBounds = YES;
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    [button setTitleColor:[UIColor colorWithHexString:@"FFFFFF"] forState:UIControlStateNormal];
    [button.titleLabel setFont:[UIFont systemFontOfSize:20]];
    [button setBackgroundColor:[UIColor colorWithHexString:@"5974A4"]];
    
    return button;
}

-(UILabel*) createLabelWithText:(NSString*)text frame:(CGRect) frame fontSize:(CGFloat)fontSize
{
    UILabel* lb = [[UILabel alloc] init];
    lb.top = frame.origin.y;
    lb.left = frame.origin.x;
    lb.width = frame.size.width;
    lb.height = frame.size.height;
    lb.font = [UIFont systemFontOfSize:fontSize];
    lb.numberOfLines = 0;
    lb.textAlignment = NSTextAlignmentLeft;
    lb.text = text;
    
    return lb;
}

#pragma  mark - actions



@end
